package com.xinhe.web.controller;

import com.querydsl.core.QueryResults;
import com.xinhe.web.annotation.WebUsed;
import com.xinhe.web.common.Result;
import com.xinhe.web.entity.SeckillGoods;
import com.xinhe.web.response.SeckillGoodsView;
import com.xinhe.web.service.SeckillGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "秒杀商品列表", tags = {"秒杀商品列表"})
@RestController
@RequestMapping(value = {"/seckillGoods"}, produces = {"application/json;charset=UTF-8"})

public class SeckillGoodsController {
   @Autowired
    private SeckillGoodsService seckillGoodsService;

   @WebUsed
    @ApiOperation(httpMethod = "GET", value = "分页查询秒杀商品")
    @RequestMapping({"/pageSeckillGoods"})
    public QueryResults<SeckillGoodsView> pageSeckillGoods(Long goodsId,Long seckillTimeId,String remark,
            Long sellerUserId,String keyword) {
        return this.seckillGoodsService.pageSeckillGoods(goodsId, seckillTimeId, remark,
                 sellerUserId,keyword);
    }

    @ApiOperation(httpMethod = "GET", value = "分页查询秒杀商品（商家）")
    @RequestMapping({"/pageSeckillGoodsBySeller"})
    public QueryResults<SeckillGoodsView> pageSeckillGoodsBySeller(Long goodsId,Long seckillTimeId,String remark,
                                                                   Long sellerUserId,String keyword) {
        return this.seckillGoodsService.pageSeckillGoodsBySeller(goodsId, seckillTimeId, remark,
                sellerUserId,keyword);
    }

    @WebUsed
    @ApiOperation(httpMethod = "POST", value = "保存秒杀商品")
    @RequestMapping({"/saveSeckillGoods"})
    public Result saveSeckillGoods(Long goodsId, Long seckillTimeId,String remark) {
        return this.seckillGoodsService.saveSeckillGoods(goodsId,seckillTimeId,remark);
    }

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "删除秒杀商品")
    @ApiImplicitParam(name = "seckillGoodsId", value = "标识", required = true)
    @RequestMapping({"/deleteSeckillGoods"})
    public Result deleteSeckillGoods(Long seckillGoodsId) {
        return this.seckillGoodsService.delete(seckillGoodsId);
    }

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "秒杀商品详情")
    @ApiImplicitParam(name = "seckillGoodsId", value = "标识", required = true)
    @RequestMapping({"/detailSeckillGoods"})
    public Result<SeckillGoods> detailSeckillGoods(Long seckillGoodsId) {
        return this.seckillGoodsService.findById(seckillGoodsId);
    }
}
